package com.prp.gwt.client.widgets.user.friend;

import java.util.HashSet;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.prp.gwt.client.user.friend.FriendListener;

public class RecommendPanel extends VerticalPanel {

	public static RecommendPanel instance;
	private RecommendListPanel recommender = new RecommendListPanel("我要推荐<br/>的用户");
	private RecommendListPanel receiver = new RecommendListPanel("接受推荐<br/>的用户");
	HashSet<Integer> set = new HashSet<Integer>();
	private Label title = new Label("我来推荐");
	private HTML recommend = new HTML("<a>推荐</a>");
	
	public static RecommendPanel getInstance() {
		if (instance == null)
			instance = new RecommendPanel();
		return instance;
	}
	
	private RecommendPanel(){
		add(title);
		add(recommender);
		add(receiver);
		recommender.addStyleName("friendRecommend-upper");
		receiver.addStyleName("friendRecommend-bottom");
		add(recommend);
		recommend.addStyleName("friendRecommend-bottom");
		recommend.addStyleName("friendRecommend-text");
		title.addStyleName("friendList-title");
		recommend.addClickHandler(new ClickHandler(){
			@Override
			public void onClick(ClickEvent event) {
				if(recommender.set.isEmpty() || recommender.set.isEmpty())
					return;
				FriendListener.getInstance().recommend(recommender.set, receiver.set);
				recommender.init();
				receiver.init();
				set.clear();
			}
		});
	}
	
	public void addSuggest(String suggestion) {
		RecommendListPanel.getSuggestOracle().add(suggestion);
	}
	
}
